import regeneratorRuntime, { async } from '../lib/runtime/runtime';

export const  addCartApi= (data) =>{
	return uni.$ajax.post({
		url: 'mp/shoppingCart/add',
		data: data
	})
}

export const  updateCartApi= (data) =>{
	return uni.$ajax.post({
		url: 'mp/shoppingCart/sub',
		data: data
	})
}
export const  clearCartApi= () =>{
	return uni.$ajax.delete({
		url: 'mp/shoppingCart/clean',
		
	})
}

export const  setMealDishDetailsApi= (id) =>{
	return uni.$ajax.get({
		url: `mp/setmeal/${id}`,
		
	})
}

export const  dishListApi= (data) =>{
	return uni.$ajax.get({
		url: 'mp/dish/list',
		data: { ...data }
	})
}
export const  setmealListApi= (data) =>{
	return uni.$ajax.get({
		url: 'mp/setmeal/list',
		data: { ...data }
	})
}
export const categoryListApi = () => {
	return uni.$ajax.get({
		url: "mp/category/list",
	})
}
export const cartListApi = (data) => {
	return uni.$ajax.get({
		url: "mp/shoppingCart/list",
		data: { ...data }
	})
}

// 上传头像接口
export const uploadAvatarApi = (filePath) => {
	return new Promise((resolve, reject) => {
		// 获取token用于登录验证
		const token = uni.getStorageSync('token');
		if (!token) {
			reject(new Error('请先登录'));
			return;
		}
		
		uni.uploadFile({
			url: 'https://ab.shunsukeji.com/api/mp/oss/upload', // 使用正确的mp/oss/upload接口
			filePath: filePath,
			name: 'file',
			header: {
				'token': token
			},
			success: (res) => {
				try {
					const data = JSON.parse(res.data);
					if (data.code === 0) {
						resolve(data);
					} else {
						reject(new Error(data.msg || '上传失败'));
					}
				} catch (e) {
					reject(new Error('响应数据解析失败'));
				}
			},
			fail: (error) => {
				reject(error);
			}
		});
	});
}

